package Day007_Collection_泛型_数据结构.ZuoYe;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;

public class Test2 {
    public static void main(String[] args) {

        //创建集合
        Collection<Double> coll = new ArrayList<>();
        /*coll.add(88.5);
        coll.add(39.2);
        coll.add(77.1);
        coll.add(56.8);
        coll.add(89.0);
        coll.add(99.0);
        coll.add(59.5);*/

        double[] arr = {88.5,39.2,77.1,56.8,89,99,59.5};
        for (int i = 0; i < arr.length; i++) {
            coll.add(arr[i]);
        }

        //增强for遍历
        for (Double d : coll) {
            System.out.println(d);
        }
        System.out.println("-------------");
        for (Double d : coll) {
            if (d < 60) {
                System.out.println(d);
            }
        }
        System.out.println("-------------");
        int count = 0;
        double sum = 0;
        BigDecimal age = new BigDecimal(0);
        for (Double d : coll) {
            if (d < 60) {
                count++;
            }
            sum += d;
            BigDecimal b1 = BigDecimal.valueOf(sum);
            BigDecimal b2 = BigDecimal.valueOf(coll.size());
            age = b1.divide(b2,2,BigDecimal.ROUND_HALF_UP); //72.73
        }

        //Math.round(sum/coll.size())  // 四舍五入73

        System.out.println("不及格人数:" + count); // 3
        System.out.println("平均分:" + age); // 72.73
        System.out.println("-------------");

        double max = 0;
        for (Double d : coll) {
            if (max < d) {
                max = d;
            }
        }
        System.out.println("最高分:" + max);
    }
}
